//
//  NSUserDefaultsUtil.m
//  BaiMi
//
//  Created by licl on 16/6/23.
//  Copyright © 2016年 licl. All rights reserved.
//

#import "NSUserDefaultsUtil.h"
#import "ContextUtil.h"
#import "User.h"

static NSString* KEY_LOGIN_USER         = @"key.login.user";
static NSString* KEY_LOGIN_USER_PHONE   = @"key.login.user.photoToken";
static NSString* KEY_USER_LOCATION      = @"key.user.location";//位置信息

@implementation NSUserDefaultsUtil
+(void)setUserPhone:(NSString *)phoneStr{
    NSUserDefaults * userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setObject:phoneStr forKey:@"USER_PHONE"];
    [userDefault synchronize];
}
+(NSString *)getUserPhone{
    NSString * str = [[NSUserDefaults standardUserDefaults] objectForKey:@"USER_PHONE"];
    if(!str){
       return nil;
    }
    return str;
}
+(void)setToken:(NSString *)token{
    NSUserDefaults *userDefault = [NSUserDefaults  standardUserDefaults];
    [userDefault setObject:token forKey:@"GET_TOKEN"];
    [userDefault synchronize];
}
+(NSString *)gettoken{
    NSString *dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"GET_TOKEN"];
    if (!dict) {
        return nil;
    }
    
    return dict;
}

+(void)setUserWithAccount:(User *)user{
    NSUserDefaults *userDefault = [NSUserDefaults  standardUserDefaults];
    [userDefault setObject:[User Users:user] forKey:@"user"];
    [userDefault synchronize];
}

+(User *)getLoginUser{
    NSDictionary *dict = [[NSUserDefaults standardUserDefaults] dictionaryForKey:KEY_LOGIN_USER];
    if (!dict) {
        return nil;
    }
    User *login = [[User alloc]initWithString:[HXNSStringUtil getJsonStringFromDicOrArray:dict] error:nil];
    return login;
}
+(void)removeLoginUser{
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault removeObjectForKey:KEY_LOGIN_USER];
    [userDefault synchronize];
}


@end
